package mock.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import mock.dao.Connector;
import mock.model.User;

public class UserDAO {
private Connection con = null;
	
	public boolean checkLogin(User manager) {
		String account = manager.getAccount();
		String password = manager.getPassword();
		boolean logined = false;
		try {
			if(con == null || con.isClosed())
				con = Connector.getConnection();
			String query = "select top 1 * from Managers " +
					"where UserName = ? and Password = ?";
			PreparedStatement stm = con.prepareStatement(query);
			stm.setString(1, account);
			stm.setString(2, password);
			ResultSet rs = stm.executeQuery();
			while(rs.next()){
				logined = true;
			}
			rs.close();
			stm.close();
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return logined;
	}
}
